#!/usr/bin/env python
# encoding: utf-8
"""
SyntaxHighlight.py

Flash-based mindmap viewer

Created by Rui Carmo on 2007-01-11.
Published under the MIT license.
"""

import yaki.Engine, yaki.Store
import urlparse, re
from BeautifulSoup import *
from pygments import highlight
from pygments.lexers import *
from pygments.formatters import *

class SyntaxHighlightWikiPlugin(yaki.Engine.WikiPlugin):
  def __init__(self, registry, webapp):
    registry.register('markup',self, 'pre','syntax')
  
  def run(self, serial, tag, tagname, pagename, soup, request, response):
    try:
      lexer = tag['syntax']
    except KeyError:
      return False
    lexer = get_lexer_by_name(lexer)
    formatter = HtmlFormatter(linenos=False, cssclass='syntax')
    result = highlight(tag.contents[0], lexer, formatter)
    tag.replaceWith(result)
    return False
  